#pragma once

class CharReader2
{
public:
	typedef size_t Iterator;

	CharReader2(string &str) : m_Str(str), m_Index(0) { }

	bool End() { return m_Index >= m_Str.length(); }
	bool ReadChar(char &out) { if (m_Index < m_Str.length()) { out = m_Str[m_Index++]; return true; } else return false; }
	bool PeekChar(char &out) { if (m_Index < m_Str.length()) { out = m_Str[m_Index]; return true; } else return false; }
	bool SkipChar() { if (m_Index < m_Str.length()) { m_Index++; return true; } else return false; }
	char MustReadChar() { char ch; if (!ReadChar(ch)) throw Error("Unexpected end of file"); return ch; }
	char MustPeekChar() { char ch; if (!PeekChar(ch)) throw Error("Unexpected end of file"); return ch; }

	const Iterator & GetIterator() { return m_Index; }
	void SetIterator(const Iterator &it) { m_Index = it; }

private:
	string &m_Str;
	size_t m_Index;
};
